---
title: "Dashboard"
output:
flexdashboard::flex_dashboard:
orientation: columns
self_contained: false
vertical_layout: fill
source: embed
navbar:
- { title: "🏠 Back to Homepage", href: "../index.html" }
---
```{r block1, include=FALSE}
library(tidyverse)
library(p8105.datasets)
library(plotly)
library(flexdashboard)
library(dplyr)
library(rnoaa)
library(ggplot2)
```
```{r block2, include=FALSE, message=FALSE, fig.height=7.5, fig.width=12.5}
# Load pre-saved data
load("nynoaadat.RData")
# Clean and filter nydat
nydat <- nydat %>% drop_na()
# Clean nystationids
nystationids <- nystationids %>% drop_na()
# Clean and filter stations (also downsample for plot size)
stations <- stations %>% drop_na() %>% sample_n(25000)
```
### Spatial Distribution of NOAA GHCN Weather Stations by Elevation
```{r block3, message=FALSE, warning=FALSE, fig.height=7.5, fig.width=12.5}
# Scatterplot of station locations with color representing elevation
p1 <- ggplot(stations, aes(x = longitude, y = latitude, color = elevation)) +
geom_point(alpha = 0.7, size = 0.35) +
scale_color_viridis_c(option = "C") + # Use a color gradient suitable for elevation
labs(
x = "Longitude",
y = "Latitude",
color = "Elevation (m)") +
theme_minimal() +
theme(plot.title = element_text(hjust = 0.5) )
plotly::ggplotly(p1)
```
### Distribution of Weather Station Elevations Grouped by Recorded Element
```{r block4,message=FALSE, warning=FALSE, fig.height=7.5, fig.width=12.5}
# Boxplot of elevation by element
p2 <- ggplot(stations, aes(x = element, y = elevation)) +
geom_boxplot(fill = "lightgreen", outlier.size = 0.5, outlier.alpha = 0.5) +
labs(
x = "Element",
y = "Elevation (m)") +
theme_minimal() +
theme(
plot.title = element_text(hjust = 0.5),
axis.text.x = element_text(angle = 45, hjust = 1, size = 5) )
plotly::ggplotly(p2)
```
### Temporal Coverage of Meteorological Elements in Global Station Records
```{r block5, message=FALSE, warning=FALSE, fig.height=7.5, fig.width=12.5}
# Summarize data to get the number of stations recording each element by year
yearly_counts <- stations %>%
group_by(first_year, element) %>%
summarise(station_count = n()) %>%
ungroup()
# Line plot of station counts by year for each element with no legend
p3 <- ggplot(yearly_counts, aes(x = first_year, y = station_count, color = element, size=0.5)) +
geom_line(size = 0.4) +
labs(
x = "Year",
y = "Number of Stations") +
theme_minimal() +
theme(plot.title = element_text(hjust = 0.5),
legend.position = "none")
plotly::ggplotly(p3)
```